package com.hy.controller;

import com.hy.common.Result;
import com.hy.dto.wechatDto.WechatLoginDto;
import com.hy.entity.User;
import com.hy.service.UserService;
import com.hy.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


/**
 * 微信用户认证
 */
@RestController
@RequestMapping("/weChat/auth")
public class WechatController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result<Map<String, Object>> weChatLogin(@RequestBody WechatLoginDto request) {
        return Result.success(userService.weChatLogin(request));
    }

    /**
     * 获取当前用户信息
     */
    @GetMapping("/info")
    public Result<User> info(HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        return Result.success(userService.getById(userId));
    }
} 